package com.jwt.vpower.model
{
	import TenCMS.components.Link.TenCMSLink;
	import TenCMS.components.TenCMSBrainFULL;
	import TenCMS.components.TenCMSBrainLITE;
	import TenCMS.events.BrainEvent;
	import TenCMS.globalvariables;
	import TenCMS.utilities.RegionLoader;
	
	import com.AppFacade;
	
	import flash.display.Sprite;
	import flash.events.*;
	import flash.external.ExternalInterface;
	import flash.text.TextFormat;

	public class TenCMSBrainLite extends Sprite
	{
		/*----------------------------------------------------------------
		* 10CMS VARIABLES												*/
		
		public static var CMSBRAIN						:TenCMSBrainLITE
		public static var REGIONLOADER					:TenCMS.utilities.RegionLoader;
		
		
		
		public function TenCMSBrainLite()
		{
			
		}
		
		public function init():void{
			CMSBRAIN						= 			new TenCMSBrainLITE("E3D68038-3BB3-4C90-AB83-538D0BBAB443", "ShellVpower_Application");
			CMSBRAIN.contentOnly = false;
			CMSBRAIN.showGotoScreen = false;
			CMSBRAIN.addCMSPages = false;
			CMSBRAIN.addEventListener(BrainEvent.XML_RECEIVED,onXMLReceived);
			CMSBRAIN.addEventListener(BrainEvent.PAGE_ENTERED, onPageEntered);
			AppFacade.CMSBRAIN=CMSBRAIN
			addChild(CMSBRAIN);
			//CMSBRAIN.useCacheBuster=true;
			CMSBRAIN.start10CMS();
		}
		
		private function onXMLReceived($e:BrainEvent):void{
			
			$e.preventDefault();
			CMSBRAIN.removeEventListener(BrainEvent.XML_RECEIVED,onXMLReceived);
			
			if (CMSBRAIN.xml.configuration == undefined)
			{
			CMSBRAIN.xml.appendChild(<c9onfiguration><videothemes><theme bg="0xF7D117" txt="0x1A1A1A" alpha="90" name="Solid Yellow" id="v1"/><theme bg="0xFAE374" txt="0x1A1A1A" alpha="90" name="Tint Yellow" id="v2"/></videothemes><videoskinurl link="VideoPlayer.swf"/><language label="Latin" data="1" id="1" char_set="latin" heading_font="verdana_bold" body_font="verdana" other_font="" font_size="11" font_direction="ltr"/></configuration>);			
			}
	
			
			REGIONLOADER = RegionLoader.getregionloader(XML(CMSBRAIN.xml.configuration.language),true, false);
			REGIONLOADER.addEventListener(RegionLoader.ALLFONTSLOADED, allFontsLoaded);
			AppFacade.REGIONLOADER=REGIONLOADER
			
			dispatchEvent(new Event("xmlLoaded"));
			
			
			
		}
		/**
		 * When fonts have been loaded from the Shell Static server
		 * 
		 * @param	event
		 */
		
		private function allFontsLoaded(event:Event):void
		{
			REGIONLOADER.removeEventListener(RegionLoader.ALLFONTSLOADED, allFontsLoaded);
			CMSBRAIN.navigate10CMSLink(new TenCMSLink(CMSBRAIN._homepageID, TenCMSLink.TYPEPAGE));
		}
		private function onPageEntered(event:BrainEvent):void
		{
			dispatchEvent(new Event("BrainLoaded"));
			
		}
		
		public function getBrain():TenCMSBrainLITE{
			return CMSBRAIN;
		}
		
	}
}